package com.example.wanjinyou.service.impl;

import com.example.wanjinyou.mapper.UserMapper;
import com.example.wanjinyou.pojo.entity.User;
import com.example.wanjinyou.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.wanjinyou.vo.UserVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr.Chen
 * @since 2022-10-20
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    //根据用户id查找用户信息
    @Override
    public User findUserById(Long authorId) {
            return userMapper.selectById(authorId);
    }

    //根据用户id查找用户信息转换为vo对象
    @Override
    public UserVo findUserVoById(Long authorId) {
        User user = userMapper.selectById(authorId);
        //如果为空, 设为默认值
        if( user == null) {
            user = new User();
            user.setUserId(1L);
            user.setNickName("默认用户");
        }
        UserVo userVo = new UserVo();
        BeanUtils.copyProperties(user,userVo);
        return userVo;
    }
}
